﻿Imports 华容道.ModGloble
Imports 华容道.ModHRDFile
Imports System.IO

Public Class Frmmain
    Public Ms As Choose                    ' 记录鼠标按下时的坐标
    Dim Number As Integer = 0              ' 移动次数
    Dim HRDFile As String

    ' 获取鼠标的运动方向    
    Public Function GetMouseMovement()
        ' 比较鼠标按下坐标和松开的坐标的x,y之差,即鼠标的横向移动值x_value和纵向移动值y_value
        ' 当 x_value > y_value 说明鼠标不是左移动即是右移动
        ' 最后通过差值x_value,y_value的正负即可判断鼠标向什么方向移动

        Dim rStr As String = "NoMove"             ' 定义返回值，默认没有移动

        ' x_value横向移动值，y_value纵向移动值
        Dim x_value As Integer = System.Windows.Forms.Control.MousePosition.X - Ms.x
        Dim y_value As Integer = System.Windows.Forms.Control.MousePosition.Y - Ms.y

        If Math.Abs(x_value) > Math.Abs(y_value) Then
            If x_value < 0 Then
                rStr = "Left"
            Else
                rStr = "Right"
            End If
        ElseIf Math.Abs(y_value) > Math.Abs(x_value) Then
            If y_value < 0 Then
                rStr = "Top"
            Else
                rStr = "Bottom"
            End If
        End If

        Return rStr
    End Function

    ' 检测某方向是否可以移动
    ' pic       图片
    ' picMove   图片检测的方向
    ' picType   图片类型： 1.横向两个      2.纵向两个      3.一个        4.4个     
    Public Function CheckMove(ByVal Pic As PictureBox, picMove As String, picType As Integer)
        Dim rValue As Boolean = False

        ' 判断
        Select Case picMove
            Case "Right"
                Select Case picType
                    Case 1
                        If Pic_Chess_Choose_1.Location = New Point(Pic.Left + 180, Pic.Top) Or Pic_Chess_Choose_2.Location = New Point(Pic.Left + 180, Pic.Top) Then
                            rValue = True
                        End If
                    Case 2
                        If (Pic_Chess_Choose_1.Location = New Point(Pic.Left + 90, Pic.Top) And Pic_Chess_Choose_2.Location = New Point(Pic.Left + 90, Pic.Top + 90)) Or (Pic_Chess_Choose_1.Location = New Point(Pic.Left + 90, Pic.Top + 90) And Pic_Chess_Choose_2.Location = New Point(Pic.Left + 90, Pic.Top)) Then
                            rValue = True
                        End If
                    Case 3
                        If Pic_Chess_Choose_1.Location = New Point(Pic.Left + 90, Pic.Top) Or Pic_Chess_Choose_2.Location = New Point(Pic.Left + 90, Pic.Top) Then
                            rValue = True
                        End If
                    Case 4
                        If (Pic_Chess_Choose_1.Location = New Point(Pic.Left + 180, Pic.Top) And Pic_Chess_Choose_2.Location = New Point(Pic.Left + 180, Pic.Top + 90)) Or (Pic_Chess_Choose_1.Location = New Point(Pic.Left + 180, Pic.Top + 90) And Pic_Chess_Choose_2.Location = New Point(Pic.Left + 180, Pic.Top)) Then
                            rValue = True
                        End If
                End Select
            Case "Left"
                Select Case picType
                    Case 1, 3
                        If Pic_Chess_Choose_1.Location = New Point(Pic.Left - 90, Pic.Top) Or Pic_Chess_Choose_2.Location = New Point(Pic.Left - 90, Pic.Top) Then
                            rValue = True
                        End If
                    Case 2, 4
                        If (Pic_Chess_Choose_1.Location = New Point(Pic.Left - 90, Pic.Top) And Pic_Chess_Choose_2.Location = New Point(Pic.Left - 90, Pic.Top + 90)) Or (Pic_Chess_Choose_1.Location = New Point(Pic.Left - 90, Pic.Top + 90) And Pic_Chess_Choose_2.Location = New Point(Pic.Left - 90, Pic.Top)) Then
                            rValue = True
                        End If
                End Select
            Case "Top"
                Select Case picType
                    Case 1, 4
                        If (Pic_Chess_Choose_1.Location = New Point(Pic.Left, Pic.Top - 90) And Pic_Chess_Choose_2.Location = New Point(Pic.Left + 90, Pic.Top - 90)) Or (Pic_Chess_Choose_2.Location = New Point(Pic.Left, Pic.Top - 90) And Pic_Chess_Choose_1.Location = New Point(Pic.Left + 90, Pic.Top - 90)) Then
                            rValue = True
                        End If
                    Case 2, 3
                        If Pic_Chess_Choose_1.Location = New Point(Pic.Left, Pic.Top - 90) Or Pic_Chess_Choose_2.Location = New Point(Pic.Left, Pic.Top - 90) Then
                            rValue = True
                        End If
                End Select
            Case "Bottom"
                Select Case picType
                    Case 1
                        If (Pic_Chess_Choose_1.Location = New Point(Pic.Left, Pic.Top + 90) And Pic_Chess_Choose_2.Location = New Point(Pic.Left + 90, Pic.Top + 90)) Or ((Pic_Chess_Choose_2.Location = New Point(Pic.Left, Pic.Top + 90) And Pic_Chess_Choose_1.Location = New Point(Pic.Left + 90, Pic.Top + 90))) Then
                            rValue = True
                        End If
                    Case 2
                        If Pic_Chess_Choose_1.Location = New Point(Pic.Left, Pic.Top + 180) Or Pic_Chess_Choose_2.Location = New Point(Pic.Left, Pic.Top + 180) Then
                            rValue = True
                        End If
                    Case 3
                        If Pic_Chess_Choose_1.Location = New Point(Pic.Left, Pic.Top + 90) Or Pic_Chess_Choose_2.Location = New Point(Pic.Left, Pic.Top + 90) Then
                            rValue = True
                        End If
                    Case 4
                        If (Pic_Chess_Choose_1.Location = New Point(Pic.Left, Pic.Top + 180) And Pic_Chess_Choose_2.Location = New Point(Pic.Left + 90, Pic.Top + 180)) Or (Pic_Chess_Choose_1.Location = New Point(Pic.Left + 90, Pic.Top + 180) And Pic_Chess_Choose_2.Location = New Point(Pic.Left, Pic.Top + 180)) Then
                            rValue = True
                        End If
                End Select
        End Select

        Return rValue
    End Function

    ' 显示可以移动方向的choosePic
    ' pic       图片
    ' picMove   图片检测的方向
    ' picType   图片类型： 1.横向两个      2.纵向两个      3.一个        4.4个 
    Public Sub ShowChoosePic(ByVal pic As PictureBox, picMove As String, picType As Integer)
        Select Case picMove
            Case "Right"
                Select Case picType
                    Case 1
                        If Pic_Chess_Choose_1.Location = New Point(pic.Left + 180, pic.Top) Then
                            Pic_Chess_Choose_1.Visible = True
                        Else
                            Pic_Chess_Choose_2.Visible = True
                        End If
                    Case 2, 4
                        Pic_Chess_Choose_1.Visible = True
                        Pic_Chess_Choose_2.Visible = True
                    Case 3
                        If Pic_Chess_Choose_1.Location = New Point(pic.Left + 90, pic.Top) Then
                            Pic_Chess_Choose_1.Visible = True
                        Else
                            Pic_Chess_Choose_2.Visible = True
                        End If
                End Select
            Case "Left"
                Select Case picType
                    Case 1, 3
                        If Pic_Chess_Choose_1.Location = New Point(pic.Left - 90, pic.Top) Then
                            Pic_Chess_Choose_1.Visible = True
                        Else
                            Pic_Chess_Choose_2.Visible = True
                        End If
                    Case 2, 4
                        Pic_Chess_Choose_1.Visible = True
                        Pic_Chess_Choose_2.Visible = True
                End Select
            Case "Top"
                Select Case picType
                    Case 1, 4
                        Pic_Chess_Choose_1.Visible = True
                        Pic_Chess_Choose_2.Visible = True
                    Case 2, 3
                        If Pic_Chess_Choose_1.Location = New Point(pic.Left, pic.Top - 90) Then
                            Pic_Chess_Choose_1.Visible = True
                        Else
                            Pic_Chess_Choose_2.Visible = True
                        End If
                End Select
            Case "Bottom"
                Select Case picType
                    Case 1, 4
                        Pic_Chess_Choose_1.Visible = True
                        Pic_Chess_Choose_2.Visible = True
                    Case 2
                        If Pic_Chess_Choose_1.Location = New Point(pic.Left, pic.Top + 180) Then
                            Pic_Chess_Choose_1.Visible = True
                        Else
                            Pic_Chess_Choose_2.Visible = True
                        End If
                    Case 3
                        If Pic_Chess_Choose_1.Location = New Point(pic.Left, pic.Top + 90) Then
                            Pic_Chess_Choose_1.Visible = True
                        Else
                            Pic_Chess_Choose_2.Visible = True
                        End If
                End Select
        End Select
    End Sub

    ' 移动棋子
    ' pic       图片
    ' picMove   图片检测的方向
    ' picType   图片类型： 1.横向两个      2.纵向两个      3.一个        4.4个 
    Public Sub MoveChessman(ByVal pic As PictureBox, picMove As String, picType As Integer)
        Select Case picMove
            Case "Right"
                Select Case picType
                    Case 1
                        If Pic_Chess_Choose_1.Location = New Point(pic.Left + 180, pic.Top) Then
                            Pic_Chess_Choose_1.Left -= 180
                        Else
                            Pic_Chess_Choose_2.Left -= 180
                        End If
                        pic.Left += 90
                    Case 2
                        Pic_Chess_Choose_1.Left -= 90
                        Pic_Chess_Choose_2.Left -= 90
                        pic.Left += 90
                    Case 3
                        If Pic_Chess_Choose_1.Location = New Point(pic.Left + 90, pic.Top) Then
                            Pic_Chess_Choose_1.Left -= 90
                        Else
                            Pic_Chess_Choose_2.Left -= 90
                        End If
                        pic.Left += 90
                    Case 4
                        Pic_Chess_Choose_1.Left -= 180
                        Pic_Chess_Choose_2.Left -= 180
                        pic.Left += 90
                End Select
            Case "Left"
                Select Case picType
                    Case 1
                        If Pic_Chess_Choose_1.Location = New Point(pic.Left - 90, pic.Top) Then
                            Pic_Chess_Choose_1.Left += 180
                        Else
                            Pic_Chess_Choose_2.Left += 180
                        End If
                        pic.Left -= 90
                    Case 2
                        Pic_Chess_Choose_1.Left += 90
                        Pic_Chess_Choose_2.Left += 90
                        pic.Left -= 90
                    Case 3
                        If Pic_Chess_Choose_1.Location = New Point(pic.Left - 90, pic.Top) Then
                            Pic_Chess_Choose_1.Left += 90
                        Else
                            Pic_Chess_Choose_2.Left += 90
                        End If
                        pic.Left -= 90
                    Case 4
                        Pic_Chess_Choose_1.Left += 180
                        Pic_Chess_Choose_2.Left += 180
                        pic.Left -= 90
                End Select
            Case "Top"
                Select Case picType
                    Case 1
                        Pic_Chess_Choose_1.Top += 90
                        Pic_Chess_Choose_2.Top += 90
                        pic.Top -= 90
                    Case 2
                        If Pic_Chess_Choose_1.Location = New Point(pic.Left, pic.Top - 90) Then
                            Pic_Chess_Choose_1.Top += 180
                        Else
                            Pic_Chess_Choose_2.Top += 180
                        End If
                        pic.Top -= 90
                    Case 3
                        If Pic_Chess_Choose_1.Location = New Point(pic.Left, pic.Top - 90) Then
                            Pic_Chess_Choose_1.Top += 90
                        Else
                            Pic_Chess_Choose_2.Top += 90
                        End If
                        pic.Top -= 90
                    Case 4
                        Pic_Chess_Choose_1.Top += 180
                        Pic_Chess_Choose_2.Top += 180
                        pic.Top -= 90
                End Select
            Case "Bottom"
                Select Case picType
                    Case 1
                        Pic_Chess_Choose_1.Top -= 90
                        Pic_Chess_Choose_2.Top -= 90
                        pic.Top += 90
                    Case 2
                        If Pic_Chess_Choose_1.Location = New Point(pic.Left, pic.Top + 180) Then
                            Pic_Chess_Choose_1.Top -= 180
                        Else
                            Pic_Chess_Choose_2.Top -= 180
                        End If
                        pic.Top += 90
                    Case 3
                        If Pic_Chess_Choose_1.Location = New Point(pic.Left, pic.Top + 90) Then
                            Pic_Chess_Choose_1.Top -= 90
                        Else
                            Pic_Chess_Choose_2.Top -= 90
                        End If
                        pic.Top += 90
                    Case 4
                        Pic_Chess_Choose_1.Top -= 180
                        Pic_Chess_Choose_2.Top -= 180
                        pic.Top += 90
                End Select
        End Select
    End Sub

    ' 保存为HRD文件
    Public Sub SaveAsHRDFile(ByVal savePath As String)
        Dim Txt As String = "华容道棋盘文件，如不清楚格式请不要修改" & vbCrLf
        Txt += "V" & My.Application.Info.Version.ToString & vbCrLf
        Txt += "Number=" & Lbl_Number.Text & vbCrLf
        Txt += "HV" & vbCrLf
        If Pic_Chessman_MC.Width = 90 Then
            Txt += 2 & vbCrLf
        Else
            Txt += 1 & vbCrLf
        End If
        If Pic_Chessman_ZY.Width = 90 Then
            Txt += 2 & vbCrLf
        Else
            Txt += 1 & vbCrLf
        End If
        If Pic_Chessman_ZF.Width = 90 Then
            Txt += 2 & vbCrLf
        Else
            Txt += 1 & vbCrLf
        End If
        If Pic_Chessman_HZ.Width = 90 Then
            Txt += 2 & vbCrLf
        Else
            Txt += 1 & vbCrLf
        End If
        If Pic_Chessman_GY.Width = 90 Then
            Txt += 2 & vbCrLf
        Else
            Txt += 1 & vbCrLf
        End If
        Txt += "Position" & vbCrLf
        Txt += Pic_Chessman_CC.Left & "," & Pic_Chessman_CC.Top & vbCrLf
        Txt += Pic_Chessman_MC.Left & "," & Pic_Chessman_MC.Top & vbCrLf
        Txt += Pic_Chessman_ZY.Left & "," & Pic_Chessman_ZY.Top & vbCrLf
        Txt += Pic_Chessman_ZF.Left & "," & Pic_Chessman_ZF.Top & vbCrLf
        Txt += Pic_Chessman_HZ.Left & "," & Pic_Chessman_HZ.Top & vbCrLf
        Txt += Pic_Chessman_GY.Left & "," & Pic_Chessman_GY.Top & vbCrLf
        Txt += Pic_Chessman_Zu_1.Left & "," & Pic_Chessman_Zu_1.Top & vbCrLf
        Txt += Pic_Chessman_Zu_2.Left & "," & Pic_Chessman_Zu_2.Top & vbCrLf
        Txt += Pic_Chessman_Zu_3.Left & "," & Pic_Chessman_Zu_3.Top & vbCrLf
        Txt += Pic_Chessman_Zu_4.Left & "," & Pic_Chessman_Zu_4.Top & vbCrLf
        Txt += Pic_Chess_Choose_1.Left & "," & Pic_Chess_Choose_1.Top & vbCrLf
        Txt += Pic_Chess_Choose_2.Left & "," & Pic_Chess_Choose_2.Top

        Dim SW As StreamWriter = New StreamWriter(savePath, False, System.Text.Encoding.Default)
        SW.Write(Txt)
        SW.Close()
    End Sub

    ' 初始化
    Public Sub Init()
        Pic_Chess_Choose_1.Visible = False
        Pic_Chess_Choose_2.Visible = False
    End Sub

    ' 初始化菜单
    Public Sub InitMenu()
        ' 先检查文件夹是否存在
        If Directory.Exists(My.Application.Info.DirectoryPath & "\HRD") = False Then
            Directory.CreateDirectory(My.Application.Info.DirectoryPath & "\HRD")
        End If
        ' 依次将文件夹下文件名导入到菜单
        For Each myFile In System.IO.Directory.GetFiles(My.Application.Info.DirectoryPath & "\HRD")
            If System.IO.File.Exists(myFile) Then
                Dim i As ToolStripMenuItem = MenuStrip1.Items("Menu_InitChessboard")
                i.DropDownItems.Add(System.IO.Path.GetFileNameWithoutExtension(myFile), Nothing, AddressOf Menu_InitChessboard_Click).Name = System.IO.Path.GetFileNameWithoutExtension(myFile)
            End If
        Next
    End Sub

    ' 根据棋盘文件路径决定保存按钮可用性
    Public Function Menu_SaveChessboard_Choose(ByVal filename As String)
        If System.IO.Path.GetDirectoryName(filename) = My.Application.Info.DirectoryPath & "\HRD" Then
            Menu_Chessboard_Save.Enabled = False
        Else
            Menu_Chessboard_Save.Enabled = True
        End If
    End Function

    ' 窗体加载事件
    Private Sub Frmmain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = "华容道_" & My.Application.Info.Version.ToString & "_Beta"
        Init()
        InitMenu()          ' 初始化菜单

        HRDFile = My.Application.Info.DirectoryPath & "\HRD\" & "横刀立马.hrd"
        Menu_SaveChessboard_Choose(HRDFile)
    End Sub

    ' 初始化 标准开局
    Private Sub Menu_InitChessboard_Click(sender As Object, e As EventArgs) Handles Menu_InitChessboard.Click
        Try
            If sender.name <> "Menu_InitChessboard" And sender.name <> "Menu_InitChessboard_Add" Then
                ' 如果当前未保存，进行保存
                If (Menu_Chessboard_Save.Enabled = True) Or (Menu_SaveChessboard_Choose(HRDFile) = False And Number <> 0) Then
                    Dim MSGR As DialogResult = MsgBox("您已经移动了棋子，是否进行保存，以便下次继续进行棋局？", vbYesNoCancel, "警告")
                    If MSGR = DialogResult.Yes Then
                        ' 保存并进入初始化棋盘
                        If Menu_Chessboard_Save.Enabled = True Then
                            Call Menu_Chessboard_Save_Click(Nothing, Nothing)
                        Else
                            Call Menu_Chessboard_SaveAs_Click(Nothing, Nothing)
                        End If
                    ElseIf MSGR = DialogResult.Cancel Then
                        ' 取消返回棋盘
                        Exit Sub
                    End If
                End If
                Number = 0
                Lbl_Number.Text = 0

                HRDFile = My.Application.Info.DirectoryPath & "\HRD\" & sender.name & ".hrd"
                Menu_SaveChessboard_Choose(HRDFile)

                initChessboard(My.Application.Info.DirectoryPath & "\HRD\" & sender.name & ".hrd")

            End If
        Catch ex As Exception
        End Try
    End Sub

    ' 添加初始化棋盘文件
    Private Sub Menu_InitChessboard_Add_Click(sender As Object, e As EventArgs) Handles Menu_InitChessboard_Add.Click
        Dim OFD As OpenFileDialog = New OpenFileDialog
        OFD.Filter = "华容道棋盘文件(*.hrd)|*.hrd"
        If OFD.ShowDialog = DialogResult.OK Then
            Dim savePath As String = My.Application.Info.DirectoryPath & "\HRD\" & IO.Path.GetFileName(OFD.FileName)

            If File.Exists(My.Application.Info.DirectoryPath & "\HRD\" & IO.Path.GetFileName(OFD.FileName)) Then
                Dim MSGR As DialogResult = MsgBox("已存在该名称文件，请问是否覆盖", vbYesNo, "询问")

                If MSGR = DialogResult.Yes Then
                    Dim SR As StreamReader = New StreamReader(OFD.FileName)
                    Dim txt As String = SR.ReadToEnd
                    SR.Close()

                    Dim SW As StreamWriter = New StreamWriter(savePath, False, System.Text.Encoding.Default)
                    SW.Write(txt)
                    SW.Close()
                    InitMenu()
                Else
                    MsgBox("已取消覆盖！",, "提示")
                End If
            Else
                FileCopy(OFD.FileName, My.Application.Info.DirectoryPath & "\HRD\" & IO.Path.GetFileName(OFD.FileName))
                InitMenu()
            End If
        End If
    End Sub

    ' 打开棋盘
    Private Sub Menu_Chessboard_Open_Click(sender As Object, e As EventArgs) Handles Menu_Chessboard_Open.Click
        Dim OFD As OpenFileDialog = New OpenFileDialog
        OFD.Filter = "华容道棋盘文件(*.hrd)|*.hrd"
        If OFD.ShowDialog = DialogResult.OK Then
            initChessboard(OFD.FileName)

            Number = GetNumber(OFD.FileName)
            Lbl_Number.Text = Number

            HRDFile = OFD.FileName
            Menu_SaveChessboard_Choose(HRDFile)
        End If
        OFD.Dispose()
    End Sub


    ' 保存棋盘
    Private Sub Menu_Chessboard_Save_Click(sender As Object, e As EventArgs) Handles Menu_Chessboard_Save.Click
        saveAsHRDFile(HRDFile)
    End Sub

    ' 另存为
    Private Sub Menu_Chessboard_SaveAs_Click(sender As Object, e As EventArgs) Handles Menu_Chessboard_SaveAs.Click
        Dim SFD As SaveFileDialog = New SaveFileDialog
        SFD.Filter = "华容道棋盘文件(*.hrd)|*.hrd"
        If SFD.ShowDialog = DialogResult.OK Then
            If System.IO.Path.GetDirectoryName(SFD.FileName) = My.Application.Info.DirectoryPath & "\HRD" Then
                MsgBox("请不要将文件保存的程序的初始化棋盘目录", vbOKOnly, "错误")
            Else
                saveAsHRDFile(SFD.FileName)
                HRDFile = SFD.FileName
                Menu_SaveChessboard_Choose(HRDFile)
            End If
        End If
    End Sub

    ' 显示HRD文件标准
    Private Sub Menu_Help_HRDFile_Click(sender As Object, e As EventArgs) Handles Menu_Help_HRDFile.Click
        If File.Exists(My.Application.Info.DirectoryPath & "\HRD文件标准.html") Then
            System.Diagnostics.Process.Start(My.Application.Info.DirectoryPath & "\HRD文件标准.html")
        Else
            MsgBox("文件不存在")
        End If
    End Sub

    ' 访问作者qq空间
    Private Sub Menu_Help_Visit_Click(sender As Object, e As EventArgs) Handles Menu_Help_Visit.Click
        System.Diagnostics.Process.Start("https://user.qzone.qq.com/2378736060/infocenter")
    End Sub

    ' 退出
    Private Sub Menu_Chessboard_Close_Click(sender As Object, e As EventArgs) Handles Menu_Chessboard_Close.Click
        End
    End Sub

    ' 曹操
    Private Sub Pic_Chessman_CC_MouseDown(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_CC.MouseDown
        ' 检测右面是否存在空位
        If checkMove(Pic_Chessman_CC, "Right", 4) Then
            showChoosePic(Pic_Chessman_CC, "Right", 4)
        End If
        ' 检测左面是否存在空位
        If checkMove(Pic_Chessman_CC, "Left", 4) Then
            showChoosePic(Pic_Chessman_CC, "Left", 4)
        End If
        ' 检测上面是否存在空位
        If checkMove(Pic_Chessman_CC, "Top", 4) Then
            showChoosePic(Pic_Chessman_CC, "Top", 4)
        End If
        ' 检测下面是否存在空位        
        If checkMove(Pic_Chessman_CC, "Bottom", 4) Then
            showChoosePic(Pic_Chessman_CC, "Bottom", 4)
        End If

        Ms.x = System.Windows.Forms.Control.MousePosition.X
        Ms.y = System.Windows.Forms.Control.MousePosition.Y
    End Sub

    Private Sub Pic_Chessman_CC_MouseUp(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_CC.MouseUp
        If getMouseMovement() <> "NoMove" Then
            If checkMove(Pic_Chessman_CC, getMouseMovement(), 4) Then
                moveChessman(Pic_Chessman_CC, getMouseMovement(), 4)

                Number += 1
                Lbl_Number.Text = Number

                If Pic_Chessman_CC.Location = New Point(90, 270) Then   ' 成功
                    MsgBox("干的漂亮！你一共走了" & Number & "步！")
                End If
            End If
            End If
        Init()
    End Sub

    ' 马超
    Private Sub Pic_Chessman_MC_MouseDown(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_MC.MouseDown
        Dim type As Integer = 1
        If Pic_Chessman_MC.Width = 90 Then
            type = 2
        End If

        ' 检测右面是否存在空位
        If checkMove(Pic_Chessman_MC, "Right", type) Then
            showChoosePic(Pic_Chessman_MC, "Right", type)
        End If
        ' 检测左面是否存在空位
        If checkMove(Pic_Chessman_MC, "Left", type) Then
            showChoosePic(Pic_Chessman_MC, "Left", type)
        End If
        ' 检测上面是否存在空位
        If checkMove(Pic_Chessman_MC, "Top", type) Then
            showChoosePic(Pic_Chessman_MC, "Top", type)
        End If
        ' 检测下面是否存在空位        
        If checkMove(Pic_Chessman_MC, "Bottom", type) Then
            showChoosePic(Pic_Chessman_MC, "Bottom", type)
        End If

        Ms.x = System.Windows.Forms.Control.MousePosition.X
        Ms.y = System.Windows.Forms.Control.MousePosition.Y
    End Sub

    Private Sub Pic_Chessman_MC_MouseUp(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_MC.MouseUp
        Dim type As Integer = 1
        If Pic_Chessman_MC.Width = 90 Then
            type = 2
        End If
        If getMouseMovement() <> "NoMove" Then
            If checkMove(Pic_Chessman_MC, getMouseMovement(), type) Then
                moveChessman(Pic_Chessman_MC, getMouseMovement(), type)
                Number += 1
                Lbl_Number.Text = Number
            End If
        End If
        Init()
    End Sub

    ' 赵云
    Private Sub Pic_Chessman_ZY_MouseDown(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_ZY.MouseDown
        Dim type As Integer = 1
        If Pic_Chessman_ZY.Width = 90 Then
            type = 2
        End If
        ' 检测右面是否存在空位
        If checkMove(Pic_Chessman_ZY, "Right", type) Then
            showChoosePic(Pic_Chessman_ZY, "Right", type)
        End If
        ' 检测左面是否存在空位
        If checkMove(Pic_Chessman_ZY, "Left", type) Then
            showChoosePic(Pic_Chessman_ZY, "Left", type)
        End If
        ' 检测上面是否存在空位
        If checkMove(Pic_Chessman_ZY, "Top", type) Then
            showChoosePic(Pic_Chessman_ZY, "Top", type)
        End If
        ' 检测下面是否存在空位        
        If checkMove(Pic_Chessman_ZY, "Bottom", type) Then
            showChoosePic(Pic_Chessman_ZY, "Bottom", type)
        End If

        Ms.x = System.Windows.Forms.Control.MousePosition.X
        Ms.y = System.Windows.Forms.Control.MousePosition.Y
    End Sub

    Private Sub Pic_Chessman_ZY_MouseUp(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_ZY.MouseUp
        Dim type As Integer = 1
        If Pic_Chessman_ZY.Width = 90 Then
            type = 2
        End If
        If getMouseMovement() <> "NoMove" Then
            If checkMove(Pic_Chessman_ZY, getMouseMovement(), type) Then
                moveChessman(Pic_Chessman_ZY, getMouseMovement(), type)
                Number += 1
                Lbl_Number.Text = Number
            End If
        End If
        Init()
    End Sub

    ' 张飞
    Private Sub Pic_Chessman_ZF_MouseDown(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_ZF.MouseDown
        Dim type As Integer = 1

        If Pic_Chessman_ZF.Width = 90 Then
            type = 2
        End If
        ' 检测右面是否存在空位
        If checkMove(Pic_Chessman_ZF, "Right", type) Then
            showChoosePic(Pic_Chessman_ZF, "Right", type)
        End If
        ' 检测左面是否存在空位
        If checkMove(Pic_Chessman_ZF, "Left", type) Then
            showChoosePic(Pic_Chessman_ZF, "Left", type)
        End If
        ' 检测上面是否存在空位
        If checkMove(Pic_Chessman_ZF, "Top", type) Then
            showChoosePic(Pic_Chessman_ZF, "Top", type)
        End If
        ' 检测下面是否存在空位        
        If checkMove(Pic_Chessman_ZF, "Bottom", type) Then
            showChoosePic(Pic_Chessman_ZF, "Bottom", type)
        End If

        Ms.x = System.Windows.Forms.Control.MousePosition.X
        Ms.y = System.Windows.Forms.Control.MousePosition.Y
    End Sub

    Private Sub Pic_Chessman_ZF_MouseUp(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_ZF.MouseUp
        Dim type As Integer = 1
        If Pic_Chessman_ZF.Width = 90 Then
            type = 2
        End If
        If getMouseMovement() <> "NoMove" Then
            If checkMove(Pic_Chessman_ZF, getMouseMovement(), type) Then
                moveChessman(Pic_Chessman_ZF, getMouseMovement(), type)
                Number += 1
                Lbl_Number.Text = Number
            End If
        End If
        Init()
    End Sub

    ' 黄忠
    Private Sub Pic_Chessman_HZ_MouseDown(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_HZ.MouseDown
        Dim type As Integer = 1
        If Pic_Chessman_HZ.Width = 90 Then
            type = 2
        End If
        ' 检测右面是否存在空位
        If checkMove(Pic_Chessman_HZ, "Right", type) Then
            showChoosePic(Pic_Chessman_HZ, "Right", type)
        End If
        ' 检测左面是否存在空位
        If checkMove(Pic_Chessman_HZ, "Left", type) Then
            showChoosePic(Pic_Chessman_HZ, "Left", type)
        End If
        ' 检测上面是否存在空位
        If checkMove(Pic_Chessman_HZ, "Top", type) Then
            showChoosePic(Pic_Chessman_HZ, "Top", type)
        End If
        ' 检测下面是否存在空位        
        If checkMove(Pic_Chessman_HZ, "Bottom", type) Then
            showChoosePic(Pic_Chessman_HZ, "Bottom", type)
        End If

        Ms.x = System.Windows.Forms.Control.MousePosition.X
        Ms.y = System.Windows.Forms.Control.MousePosition.Y
    End Sub

    Private Sub Pic_Chessman_HZ_MouseUp(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_HZ.MouseUp
        Dim type As Integer = 1
        If Pic_Chessman_HZ.Width = 90 Then
            type = 2
        End If
        If getMouseMovement() <> "NoMove" Then
            If checkMove(Pic_Chessman_HZ, getMouseMovement(), type) Then
                moveChessman(Pic_Chessman_HZ, getMouseMovement(), type)
                Number += 1
                Lbl_Number.Text = Number
            End If
        End If
        Init()
    End Sub

    ' 关羽 
    Private Sub Pic_Chessman_GY_MouseDown(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_GY.MouseDown
        Dim type As Integer = 1
        If Pic_Chessman_GY.Width = 90 Then
            type = 2
        End If
        ' 检测右面是否存在空位
        If checkMove(Pic_Chessman_GY, "Right", type) Then
            showChoosePic(Pic_Chessman_GY, "Right", type)
        End If
        ' 检测左面是否存在空位
        If checkMove(Pic_Chessman_GY, "Left", type) Then
            showChoosePic(Pic_Chessman_GY, "Left", type)
        End If
        ' 检测上面是否存在空位
        If checkMove(Pic_Chessman_GY, "Top", type) Then
            showChoosePic(Pic_Chessman_GY, "Top", type)
        End If
        ' 检测下面是否存在空位
        If checkMove(Pic_Chessman_GY, "Bottom", type) Then
            showChoosePic(Pic_Chessman_GY, "Bottom", type)
        End If

        Ms.x = System.Windows.Forms.Control.MousePosition.X
        Ms.y = System.Windows.Forms.Control.MousePosition.Y
    End Sub

    Private Sub Pic_Chessman_GY_MouseUp(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_GY.MouseUp
        Dim type As Integer = 1
        If Pic_Chessman_GY.Width = 90 Then
            type = 2
        End If
        If getMouseMovement() <> "NoMove" Then
            If checkMove(Pic_Chessman_GY, getMouseMovement(), type) Then
                moveChessman(Pic_Chessman_GY, getMouseMovement(), type)
                Number += 1
                Lbl_Number.Text = Number
            End If
        End If
        Init()
    End Sub

    ' 卒1
    Private Sub Pic_Chessman_Zu_1_MouseDown(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_Zu_1.MouseDown
        ' 检测右面是否存在空位
        If checkMove(Pic_Chessman_Zu_1, "Right", 3) Then
            showChoosePic(Pic_Chessman_Zu_1, "Right", 3)
        End If
        ' 检测左面是否存在空位
        If checkMove(Pic_Chessman_Zu_1, "Left", 3) Then
            showChoosePic(Pic_Chessman_Zu_1, "Left", 3)
        End If
        ' 检测上面是否存在空位
        If checkMove(Pic_Chessman_Zu_1, "Top", 3) Then
            showChoosePic(Pic_Chessman_Zu_1, "Top", 3)
        End If
        ' 检测上面是否存在空位
        If checkMove(Pic_Chessman_Zu_1, "Bottom", 3) Then
            showChoosePic(Pic_Chessman_Zu_1, "Bottom", 3)
        End If

        Ms.x = System.Windows.Forms.Control.MousePosition.X
        Ms.y = System.Windows.Forms.Control.MousePosition.Y
    End Sub

    Private Sub Pic_Chessman_Zu_1_MouseUp(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_Zu_1.MouseUp
        If getMouseMovement() <> "NoMove" Then
            If checkMove(Pic_Chessman_Zu_1, getMouseMovement(), 3) Then
                moveChessman(Pic_Chessman_Zu_1, getMouseMovement(), 3)
                Number += 1
                Lbl_Number.Text = Number
            End If
        End If
        Init()
    End Sub

    ' 卒2
    Private Sub Pic_Chessman_Zu_2_MouseDown(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_Zu_2.MouseDown
        ' 检测右面是否存在空位
        If checkMove(Pic_Chessman_Zu_2, "Right", 3) Then
            showChoosePic(Pic_Chessman_Zu_2, "Right", 3)
        End If
        ' 检测左面是否存在空位
        If checkMove(Pic_Chessman_Zu_2, "Left", 3) Then
            showChoosePic(Pic_Chessman_Zu_2, "Left", 3)
        End If
        ' 检测上面是否存在空位        
        If checkMove(Pic_Chessman_Zu_2, "Top", 3) Then
            showChoosePic(Pic_Chessman_Zu_2, "Top", 3)
        End If
        ' 检测上面是否存在空位
        If checkMove(Pic_Chessman_Zu_2, "Bottom", 3) Then
            showChoosePic(Pic_Chessman_Zu_2, "Bottom", 3)
        End If

        Ms.x = System.Windows.Forms.Control.MousePosition.X
        Ms.y = System.Windows.Forms.Control.MousePosition.Y
    End Sub

    Private Sub Pic_Chessman_Zu_2_MouseUp(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_Zu_2.MouseUp
        If getMouseMovement() <> "NoMove" Then
            If checkMove(Pic_Chessman_Zu_2, getMouseMovement(), 3) Then
                moveChessman(Pic_Chessman_Zu_2, getMouseMovement(), 3)
                Number += 1
                Lbl_Number.Text = Number
            End If
        End If
        Init()
    End Sub

    ' 卒3
    Private Sub Pic_Chessman_Zu_3_MouseDown(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_Zu_3.MouseDown
        ' 检测右面是否存在空位
        If checkMove(Pic_Chessman_Zu_3, "Right", 3) Then
            showChoosePic(Pic_Chessman_Zu_3, "Right", 3)
        End If
        ' 检测左面是否存在空位
        If checkMove(Pic_Chessman_Zu_3, "Left", 3) Then
            showChoosePic(Pic_Chessman_Zu_3, "Left", 3)
        End If
        ' 检测上面是否存在空位        
        If checkMove(Pic_Chessman_Zu_3, "Top", 3) Then
            showChoosePic(Pic_Chessman_Zu_3, "Top", 3)
        End If
        ' 检测上面是否存在空位
        If checkMove(Pic_Chessman_Zu_3, "Bottom", 3) Then
            showChoosePic(Pic_Chessman_Zu_3, "Bottom", 3)
        End If

        Ms.x = System.Windows.Forms.Control.MousePosition.X
        Ms.y = System.Windows.Forms.Control.MousePosition.Y
    End Sub

    Private Sub Pic_Chessman_Zu_3_MouseUp(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_Zu_3.MouseUp
        If getMouseMovement() <> "NoMove" Then
            If checkMove(Pic_Chessman_Zu_3, getMouseMovement(), 3) Then
                moveChessman(Pic_Chessman_Zu_3, getMouseMovement(), 3)
                Number += 1
                Lbl_Number.Text = Number
            End If
        End If
        Init()
    End Sub

    ' 卒4
    Private Sub Pic_Chessman_Zu_4_MouseDown(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_Zu_4.MouseDown
        ' 检测右面是否存在空位
        If checkMove(Pic_Chessman_Zu_4, "Right", 3) Then
            showChoosePic(Pic_Chessman_Zu_4, "Right", 3)
        End If
        ' 检测左面是否存在空位
        If checkMove(Pic_Chessman_Zu_4, "Left", 3) Then
            showChoosePic(Pic_Chessman_Zu_4, "Left", 3)
        End If
        ' 检测上面是否存在空位        
        If checkMove(Pic_Chessman_Zu_4, "Top", 3) Then
            showChoosePic(Pic_Chessman_Zu_4, "Top", 3)
        End If
        ' 检测上面是否存在空位
        If checkMove(Pic_Chessman_Zu_4, "Bottom", 3) Then
            showChoosePic(Pic_Chessman_Zu_4, "Bottom", 3)
        End If

        Ms.x = System.Windows.Forms.Control.MousePosition.X
        Ms.y = System.Windows.Forms.Control.MousePosition.Y
    End Sub

    Private Sub Pic_Chessman_Zu_4_MouseUp(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_Zu_4.MouseUp
        If getMouseMovement() <> "NoMove" Then
            If checkMove(Pic_Chessman_Zu_4, getMouseMovement(), 3) Then
                moveChessman(Pic_Chessman_Zu_4, getMouseMovement(), 3)
                Number += 1
                Lbl_Number.Text = Number
            End If
        End If
        Init()
    End Sub

    ' 特效—————————————————————————————
    ' 曹操
    Private Sub Pic_Chessman_CC_MouseMove(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_CC.MouseMove
        Pic_Chessman_CC.Image = Global.华容道.My.Resources.CC_CH
    End Sub

    Private Sub Pic_Chessman_CC_MouseLeave(sender As Object, e As EventArgs) Handles Pic_Chessman_CC.MouseLeave
        Pic_Chessman_CC.Image = Global.华容道.My.Resources.CC
    End Sub

    ' 马超
    Private Sub Pic_Chessman_MC_MouseMove(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_MC.MouseMove
        If Pic_Chessman_MC.Width = 90 Then
            Pic_Chessman_MC.Image = Global.华容道.My.Resources.MC_V_CH
        Else
            Pic_Chessman_MC.Image = Global.华容道.My.Resources.MC_H_CH
        End If
    End Sub

    Private Sub Pic_Chessman_MC_MouseLeave(sender As Object, e As EventArgs) Handles Pic_Chessman_MC.MouseLeave
        If Pic_Chessman_MC.Width = 90 Then
            Pic_Chessman_MC.Image = Global.华容道.My.Resources.MC_V
        Else
            Pic_Chessman_MC.Image = Global.华容道.My.Resources.MC_H
        End If
    End Sub

    ' 赵云
    Private Sub Pic_Chessman_ZY_MouseMove(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_ZY.MouseMove
        If Pic_Chessman_ZY.Width = 90 Then
            Pic_Chessman_ZY.Image = Global.华容道.My.Resources.ZY_V_CH
        Else
            Pic_Chessman_ZY.Image = Global.华容道.My.Resources.ZY_H_CH
        End If
    End Sub

    Private Sub Pic_Chessman_ZY_MouseLeave(sender As Object, e As EventArgs) Handles Pic_Chessman_ZY.MouseLeave
        If Pic_Chessman_ZY.Width = 90 Then
            Pic_Chessman_ZY.Image = Global.华容道.My.Resources.ZY_V
        Else
            Pic_Chessman_ZY.Image = Global.华容道.My.Resources.ZY_H
        End If
    End Sub

    ' 张飞
    Private Sub Pic_Chessman_ZF_MouseMove(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_ZF.MouseMove
        If Pic_Chessman_ZF.Width = 90 Then
            Pic_Chessman_ZF.Image = Global.华容道.My.Resources.ZF_V_CH
        Else
            Pic_Chessman_ZF.Image = Global.华容道.My.Resources.ZF_H_CH
        End If
    End Sub

    Private Sub Pic_Chessman_ZF_MouseLeave(sender As Object, e As EventArgs) Handles Pic_Chessman_ZF.MouseLeave
        If Pic_Chessman_ZF.Width = 90 Then
            Pic_Chessman_ZF.Image = Global.华容道.My.Resources.ZF_V
        Else
            Pic_Chessman_ZF.Image = Global.华容道.My.Resources.ZF_H
        End If
    End Sub

    ' 黄忠
    Private Sub Pic_Chessman_HZ_MouseMove(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_HZ.MouseMove
        If Pic_Chessman_HZ.Width = 90 Then
            Pic_Chessman_HZ.Image = Global.华容道.My.Resources.HZ_V_CH
        Else
            Pic_Chessman_HZ.Image = Global.华容道.My.Resources.HZ_H_CH
        End If
    End Sub

    Private Sub Pic_Chessman_HZ_MouseLeave(sender As Object, e As EventArgs) Handles Pic_Chessman_HZ.MouseLeave
        If Pic_Chessman_HZ.Width = 90 Then
            Pic_Chessman_HZ.Image = Global.华容道.My.Resources.HZ_V
        Else
            Pic_Chessman_HZ.Image = Global.华容道.My.Resources.HZ_H
        End If
    End Sub

    ' 关羽
    Private Sub Pic_Chessman_GY_MouseMove(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_GY.MouseMove
        If Pic_Chessman_GY.Width = 90 Then
            Pic_Chessman_GY.Image = Global.华容道.My.Resources.GY_V_CH
        Else
            Pic_Chessman_GY.Image = Global.华容道.My.Resources.GY_H_CH
        End If
    End Sub

    Private Sub Pic_Chessman_GY_MouseLeave(sender As Object, e As EventArgs) Handles Pic_Chessman_GY.MouseLeave
        If Pic_Chessman_GY.Width = 90 Then
            Pic_Chessman_GY.Image = Global.华容道.My.Resources.GY_V
        Else
            Pic_Chessman_GY.Image = Global.华容道.My.Resources.GY_H
        End If
    End Sub

    ' 卒1
    Private Sub Pic_Chessman_Zu_1_MouseMove(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_Zu_1.MouseMove
        Pic_Chessman_Zu_1.Image = Global.华容道.My.Resources.Z_CH
    End Sub

    Private Sub Pic_Chessman_Zu_1_MouseLeave(sender As Object, e As EventArgs) Handles Pic_Chessman_Zu_1.MouseLeave
        Pic_Chessman_Zu_1.Image = Global.华容道.My.Resources.Z
    End Sub

    ' 卒2
    Private Sub Pic_Chessman_Zu_2_MouseMove(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_Zu_2.MouseMove
        Pic_Chessman_Zu_2.Image = Global.华容道.My.Resources.Z_CH
    End Sub

    Private Sub Pic_Chessman_Zu_2_MouseLeave(sender As Object, e As EventArgs) Handles Pic_Chessman_Zu_2.MouseLeave
        Pic_Chessman_Zu_2.Image = Global.华容道.My.Resources.Z
    End Sub

    ' 卒3
    Private Sub Pic_Chessman_Zu_3_MouseMove(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_Zu_3.MouseMove
        Pic_Chessman_Zu_3.Image = Global.华容道.My.Resources.Z_CH
    End Sub

    Private Sub Pic_Chessman_Zu_3_MouseLeave(sender As Object, e As EventArgs) Handles Pic_Chessman_Zu_3.MouseLeave
        Pic_Chessman_Zu_3.Image = Global.华容道.My.Resources.Z
    End Sub

    ' 卒4  
    Private Sub Pic_Chessman_Zu_4_MouseMove(sender As Object, e As MouseEventArgs) Handles Pic_Chessman_Zu_4.MouseMove
        Pic_Chessman_Zu_4.Image = Global.华容道.My.Resources.Z_CH
    End Sub

    Private Sub Pic_Chessman_Zu_4_MouseLeave(sender As Object, e As EventArgs) Handles Pic_Chessman_Zu_4.MouseLeave
        Pic_Chessman_Zu_4.Image = Global.华容道.My.Resources.Z
    End Sub

    Private Sub Menu_Help_Star_Click(sender As Object, e As EventArgs) Handles Menu_Help_Star.Click
        System.Diagnostics.Process.Start("https://gitee.com/ruxia-tjy/HRD")
    End Sub
End Class